package com.gsafety.libraryktx.adapter

import android.view.View
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.gsafety.libraryktx.R
import com.gsafety.libraryktx.bean.AttachBean
import com.gsafety.libraryktx.widget.AttachImageView
import com.gsafety.xuzhou.bean.SelectOpeListener

/**
 * 附件图片Adapter
 */
class RvAttachPicAdapter(data: List<AttachBean>) : BaseQuickAdapter<AttachBean, BaseViewHolder>(R.layout.common_item_attach_pic_layout, data) {
    private var listener: SelectOpeListener? = null
    var maxCount = 8

    override fun convert(helper: BaseViewHolder, item: AttachBean) {
        if (item != null) {
            val ivPic = helper.itemView.findViewById<AttachImageView>(R.id.item_attach_pic_iv)
            ivPic.getImg(item.id, item.type)
            helper.setVisible(R.id.iv_del,true)
            ivPic.setOnClickListener {
                listener?.onCheckChange(helper.adapterPosition)
            }
            if("mp4" == item.type){
                helper.setVisible(R.id.iv_video,true)
            }else{
                helper.setVisible(R.id.iv_video,false)
            }
            var delIcon = helper.itemView.findViewById<ImageView>(R.id.iv_del)
            delIcon.setOnClickListener{
                data.removeAt(helper.layoutPosition)
                footerLayout.visibility = if(helper.layoutPosition< maxCount) View.VISIBLE else View.GONE
                notifyDataSetChanged()
            }
        }
    }

    fun setListener(listener: SelectOpeListener) {
        this.listener = listener
    }
}
